{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from byzerllm.apps.utils import TagExtractor\n",
    "\n",
    "extractor = TagExtractor('''\n",
    "<_image_></_image_>\n",
    "                         大家好\n",
    "<_image_></_image_>\n",
    "''')\n",
    "\n",
    "v = extractor.extract()\n",
    "print(v.content[0].content)\n",
    "print(v.content[1].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from byzerllm.apps.utils import TagExtractor\n",
    "\n",
    "extractor = TagExtractor('''\n",
    "                         大家好\n",
    "''')\n",
    "\n",
    "v = extractor.extract()\n",
    "print(v)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-25 16:05:46.503\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-07-25 16:05:46,550\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-07-25 16:05:46,566\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "...\n",
      "这个图片里有什么？...\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'这个图片里有多只可爱的猫咪，呈现出各种姿势和表情。背景是淡棕色，猫咪的脸部特征清晰，眼睛明亮，部分猫咪周围还有红色的花朵装饰。整体风格看起来很温馨和艺术化。'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import byzerllm\n",
    "\n",
    "vl_llm = byzerllm.ByzerLLM.from_default_model(\"gpt4o_mini_chat\")\n",
    "\n",
    "\n",
    "@byzerllm.prompt()\n",
    "def what_in_image(image_path: str) -> str:\n",
    "    \"\"\"\n",
    "    {{ image }}\n",
    "    这个图片里有什么？\n",
    "    \"\"\"\n",
    "    return {\"image\": byzerllm.Image.load_image_from_path(image_path)}\n",
    "\n",
    "\n",
    "v = what_in_image.with_llm(vl_llm).run(\n",
    "    \"/Users/allwefantasy/projects/byzer-llm/images/cat1.png\"\n",
    ")\n",
    "v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-25 19:41:03.460\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-07-25 19:41:03,497\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-07-25 19:41:03,511\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'这张图片展示了多只可爱的猫咪，采用了艺术风格的绘画。猫咪们有不同的颜色和花纹，背景是浅棕色，上面还点缀着一些红色的花朵。整体画面给人一种温馨和谐的感觉。'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import byzerllm\n",
    "from byzerllm.types import ImagePath\n",
    "\n",
    "vl_llm = byzerllm.ByzerLLM.from_default_model(\"gpt4o_mini_chat\")\n",
    "\n",
    "\n",
    "@byzerllm.prompt()\n",
    "def what_in_image(image_path: ImagePath) -> str:\n",
    "    \"\"\"\n",
    "    {{ image_path }}\n",
    "    这个图片里有什么？\n",
    "    \"\"\"    \n",
    "\n",
    "\n",
    "v = what_in_image.with_llm(vl_llm).run(\n",
    "    ImagePath(value=\"/Users/allwefantasy/projects/byzer-llm/images/cat1.png\")\n",
    ")\n",
    "v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import byzerllm\n",
    "vl_llm = byzerllm.ByzerLLM.from_default_model(\"gpt4o_mini_chat\")\n",
    "\n",
    "vl_llm.chat_oai(conversations=[{\n",
    "    \"role\":\"user\",\n",
    "    \"content\":\"你好\"\n",
    "},{\n",
    "    \"role\":\"assistant\",\n",
    "    \"content\":\"你好\"\n",
    "},{\n",
    "    \"role\":\"user\",\n",
    "    \"content\":\"你是谁\"\n",
    "},])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
